package com.cloud.client;

import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chenye on 2018/3/17.
 */
@SpringBootApplication
@EnableEurekaClient
@RestController
public class EurekaClientApplication {
    public static void main(String[] args){
        ApplicationContext context = SpringApplication.run(EurekaClientApplication.class,args);
//        ((ConfigurableApplicationContext) context).addApplicationListener(new MyListener());
    }

    @Value("${server.port}")
    private String port;
    @RequestMapping("/hi")
    public String home(@RequestParam String name) throws InterruptedException {
        System.err.println("调用了");
        Thread.sleep(2000);
//        if(1==1){
//            throw new RuntimeException("123");
//        }
        return "hi "+name+",i am from port:" +port;
    }


    @Autowired
    ApplicationContext applicationContext;
    @RequestMapping("/runEvent")
    public String runEvent(){
        applicationContext.publishEvent(new MyApplicationEvent("123"));
        return "run";
    }
}
